'''
Created on Aug 25, 2011

@author: david
'''

from pspy.gae.actiondomain import PspyAction

class QScan(PspyAction):
    """
    Default Action 
    spawns index.gen
    """
    def execute(self): 
        """
        Receive results of scan...
        """
        from app.Ranger.agents import AppAgent
        import logging
        
        nxtPage = "/Ranger/QScan.gen"
        req = self.request
        vin = req.getParameter("vin","")
        did = req.getParameter("did","")
        
        logging.info("~~ vin: %s, did: %s" % (vin,did))
        
        dlr = AppAgent().getDealer(did)
        
        if not vin and did:
            # validate params
            req.setAttribute("alertMsg", "Invalid URL / Parameters. Please try again...")
            req.setAttribute("results","500::Invalid Input")
        else:
            # do we have a pin yet"
            pin = "0"
            if req.session.has_key(did):
                pin = req.session[did]
                
            logging.info("~~ PIN: %s" % pin)
            req.setAttribute("pin",pin)
            req.setAttribute("dealer", dlr.name) 
                           
            # pack and go
            req.setAttribute("results","100::Ok")
            req.setAttribute("full",1)    
            req.setResponsePage(nxtPage)        
        
        # all done
        return req.getResponse()
    
    def sess_check(self):
        return True